perf: avoid JSON/map roundtrips in ast.Value transforms#1606
Merged
anderseknert merged 1 commit intomainfrom Jun 24, 2025
Merged
perf: avoid JSON/map roundtrips in ast.Value transforms#1606anderseknert merged 1 commit intomainfrom
anderseknert merged 1 commit intomainfrom
Conversation
Leveraging the new capabilities for this in roast, we can avoid a lot of allocations by mapping directly from a source to an ast.Value rather than going via a `map[string]any`, or even JSON. For now, focus has been on how the **input** is mapped in most places of eval. This can be improved further, but the natural next step is of course to eliminate roundtrips the same way when we handle **output**, i.e. the result of evaluation. I imagine the data-heavy aggregate rules in particular could benefit greatly from this. This PR also cleans up some in LSP handlers related to input transformations, and takes a small step towards harmonizing the input format for those with the goal of eventually having a single schema to describe the common parts of all LSP request payloads. Perf impact is close to 2.9 million allocs less in the Regal lint benchmark, and greatly reduced ns/op and B/op. ``` 944216438 ns/op 2805943268 B/op 51659258 allocs/op - main 894474146 ns/op 2668457832 B/op 48779590 allocs/op - PR ``` Signed-off-by: Anders Eknert <anders@styra.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Leveraging the new capabilities for this in roast, we can avoid a lot of allocations by mapping directly from a source to an ast.Value rather than going via a
map[string]any, or even JSON. For now, focus has been on how the input is mapped in most places of eval. This can be improved further, but the natural next step is of course to eliminate roundtrips the same way when we handle output, i.e. the result of evaluation. I imagine the data-heavy aggregate rules in particular could benefit greatly from this.This PR also cleans up some in LSP handlers related to input transformations, and takes a small step towards harmonizing the input format for those with the goal of eventually having a single schema to describe the common parts of all LSP request payloads.
Perf impact is close to 2.9 million allocs less in the Regal lint benchmark, and greatly reduced ns/op and B/op.